package com.coupon.service.impl;

import com.coupon.mapper.CouponMapper;
import com.coupon.pojo.Coupon;
import com.coupon.pojo.PageObject;
import com.coupon.service.CouponService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author :wn
 * @program : coupon
 * @descript :
 * @create :2021-01-05 12:10
 */
@Service("couponService")
public class CouponServiceImpl implements CouponService {
    @Resource
    CouponMapper couponMapper;
    @Override
    public Boolean addCouponService(Coupon coupon) {
        int i = couponMapper.addCoupon(coupon);
        return i>0;
    }
    @Override
    public PageObject findAll(Integer page){
        PageObject<Coupon> pageObject = new PageObject<>();
        if(page==null){
            List<Coupon> coupons = couponMapper.selectAllNoArgs();
            pageObject.setDataList(coupons);
        }else {
            List<Coupon> coupons = couponMapper.selectAll((page - 1) * 10);

            pageObject.setDataList(coupons);
        }
        return pageObject;
    }

    @Override
    public boolean update(Integer cpId,boolean change) {
        int i = couponMapper.updateAttitude(cpId,change);
        return i>0;
    }


}
